﻿//
// Created by Administrator on 2022/1/31.
//

#include "MyDialog.h"

static void AddGroup( wxScrolledWindow *list, wxBoxSizer* sizer ){
    auto* m_panel7 = new wxPanel( list, wxID_ANY,
                            wxDefaultPosition,
                            wxDefaultSize, wxTAB_TRAVERSAL );
    wxBoxSizer* bSizer12;
    bSizer12 = new wxBoxSizer( wxHORIZONTAL );

    auto* m_button1 = new wxButton( m_panel7, wxID_ANY, wxT("MyButton"),
                              wxDefaultPosition,
                              wxDefaultSize, 0 );
    bSizer12->Add( m_button1, 0, wxALL, 5 );

    auto* m_toggleBtn2 = new wxToggleButton( m_panel7, wxID_ANY, wxT("Toggle me!"),
                                       wxDefaultPosition,
                                       wxDefaultSize, 0 );
    bSizer12->Add( m_toggleBtn2, 0, wxALL, 5 );


    m_panel7->SetSizer( bSizer12 );
    m_panel7->Layout();
    bSizer12->Fit( m_panel7 );
    sizer->Add( m_panel7, 1, wxEXPAND | wxALL, 5 );
}

/*
 * wxBoxSizer* wScrollSizer10;
 * auto * panel  = GetSubItem( m_scrolledWindow2 );
 * wScrollSizer10->Add( m_panel, 1, wxEXPAND | wxALL, 5 );
 */
static wxPanel* GetSubItem( wxScrolledWindow *parent ){
    auto* panel = new wxPanel(parent, wxID_ANY,
                              wxDefaultPosition,
                              wxDefaultSize, wxTAB_TRAVERSAL );
    wxBoxSizer* sizer;
    sizer = new wxBoxSizer(wxHORIZONTAL );

    auto* m_button1 = new wxButton(panel, wxID_ANY, wxT("MyButton"),
                                   wxDefaultPosition,
                                   wxDefaultSize, 0 );
    sizer->Add(m_button1, 0, wxALL, 5 );

    auto* m_toggleBtn2 = new wxToggleButton(panel, wxID_ANY, wxT("Toggle me!"),
                                            wxDefaultPosition,
                                            wxDefaultSize, 0 );
    sizer->Add(m_toggleBtn2, 0, wxALL, 5 );

    //
    panel->SetSizer( sizer );
    panel->Layout();
    sizer->Fit( panel );
    return panel;
}

MyDialog::MyDialog( wxWindow* parent, wxWindowID id, const wxString& title,
        const wxPoint& pos, const wxSize& size, long style )
    : wxFrame( parent, id, title, pos, size, style )
{
    this->SetSizeHints( wxDefaultSize, wxDefaultSize );

    wxBoxSizer* dialogRootBoxSizer;
    /*
     * wxBoxSizer
     *  wxScrolledWindow
     */
    dialogRootBoxSizer = new wxBoxSizer(wxVERTICAL );
    //
    m_scrolledWindow2 = new wxScrolledWindow( this, wxID_ANY,
            wxDefaultPosition,
            wxDefaultSize, wxHSCROLL|wxVSCROLL );
    m_scrolledWindow2->SetScrollRate( 5, 5 );
    //scrolledWindow sizer
    //m_scrolledWindow2->SetSizer( wScrollSizer10 );
    //    m_scrolledWindow2->Layout();
    //    wScrollSizer10->Fit(m_scrolledWindow2 );
    wxBoxSizer* wScrollSizer10;
    wScrollSizer10 = new wxBoxSizer(wxVERTICAL );

    ////////////////////////////////////////////////////////////////////////

    m_panel7 = new wxPanel( m_scrolledWindow2, wxID_ANY,
            wxDefaultPosition,
            wxDefaultSize, wxTAB_TRAVERSAL );
    wxBoxSizer* panel7_sizer;
    panel7_sizer = new wxBoxSizer(wxHORIZONTAL );

    m_button1 = new wxButton( m_panel7, wxID_ANY, wxT("MyButton"),
            wxDefaultPosition,
            wxDefaultSize, 0 );
    panel7_sizer->Add(m_button1, 0, wxALL, 5 );

    m_toggleBtn2 = new wxToggleButton( m_panel7, wxID_ANY, wxT("Toggle me!"),
            wxDefaultPosition,
            wxDefaultSize, 0 );
    panel7_sizer->Add(m_toggleBtn2, 0, wxALL, 5 );

    m_panel7->SetSizer(panel7_sizer );
    m_panel7->Layout();
    panel7_sizer->Fit(m_panel7 );
    wScrollSizer10->Add(m_panel7, 1, wxEXPAND | wxALL, 5 );

    ////////////////////////////////////////////////////////////////////////
    //build the panel
    m_panel8 = new wxPanel( m_scrolledWindow2, wxID_ANY, wxDefaultPosition,
            wxDefaultSize, wxTAB_TRAVERSAL );
    //
    wxBoxSizer* panel8_sizer;
    panel8_sizer = new wxBoxSizer(wxHORIZONTAL );

    m_button2 = new wxButton( m_panel8, wxID_ANY, wxT("MyButton"),
            wxDefaultPosition,
            wxDefaultSize, 0 );
    panel8_sizer->Add(m_button2, 0, wxALL, 5 );

    m_toggleBtn1 = new wxToggleButton( m_panel8, wxID_ANY,
            wxT("Toggle me!"), wxDefaultPosition,
            wxDefaultSize, 0 );
    panel8_sizer->Add(m_toggleBtn1, 0, wxALL, 5 );
    //

    m_panel8->SetSizer(panel8_sizer );
    m_panel8->Layout();
    panel8_sizer->Fit(m_panel8 );
    //
    wScrollSizer10->Add(m_panel8, 1, wxEXPAND | wxALL, 5 );

    ////////////////////////////////////////////////////////////////////////
    demo(wScrollSizer10);
    ///////////////////////////////////////////////////////////////////////
    //
    //scrollWindow与sizer的关系
    m_scrolledWindow2->SetSizer( wScrollSizer10 );
    m_scrolledWindow2->Layout();
    wScrollSizer10->Fit(m_scrolledWindow2 );
    dialogRootBoxSizer->Add(m_scrolledWindow2, 1, wxEXPAND | wxALL, 5 );

    ////////////////////////////////////////////////////////////////////////
    wxBoxSizer* bSizer9;
    bSizer9 = new wxBoxSizer( wxVERTICAL );

    m_panel5 = new wxPanel( this, wxID_ANY, wxDefaultPosition,
            wxDefaultSize, wxTAB_TRAVERSAL );
    bSizer9->Add( m_panel5, 1, wxEXPAND | wxALL, 5 );

    m_panel4 = new wxPanel( this, wxID_ANY, wxDefaultPosition,
            wxDefaultSize, wxTAB_TRAVERSAL );
    bSizer9->Add( m_panel4, 1, wxEXPAND | wxALL, 5 );

    m_panel3 = new wxPanel( this, wxID_ANY, wxDefaultPosition,
            wxDefaultSize, wxTAB_TRAVERSAL );
    bSizer9->Add( m_panel3, 1, wxEXPAND | wxALL, 5 );

    m_panel2 = new wxPanel( this, wxID_ANY, wxDefaultPosition,
            wxDefaultSize, wxTAB_TRAVERSAL );
    bSizer9->Add( m_panel2, 1, wxEXPAND | wxALL, 5 );

    m_panel6 = new wxPanel( this, wxID_ANY, wxDefaultPosition,
            wxDefaultSize, wxTAB_TRAVERSAL );
    bSizer9->Add( m_panel6, 1, wxEXPAND | wxALL, 5 );


    dialogRootBoxSizer->Add(bSizer9, 1, wxEXPAND, 5 );

    this->SetSizer(dialogRootBoxSizer );
    this->Layout();

    this->Centre( wxBOTH );
}

/*
 *
 */
MyDialog::~MyDialog()
{
}

//put a new list item
void MyDialog::demo(wxBoxSizer* wScrollSizer10 ) {
    m_panel8 = new wxPanel( m_scrolledWindow2, wxID_ANY,
            wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL );
    //
    wxBoxSizer* bSizer11;
    bSizer11 = new wxBoxSizer( wxHORIZONTAL );

    m_button2 = new wxButton( m_panel8, wxID_ANY, wxT("MyButton"),
            wxDefaultPosition, wxDefaultSize, 0 );
    bSizer11->Add( m_button2, 0, wxALL, 5 );

    m_toggleBtn1 = new wxToggleButton( m_panel8, wxID_ANY, wxT("Toggle me!"),
            wxDefaultPosition, wxDefaultSize, 0 );
    bSizer11->Add( m_toggleBtn1, 0, wxALL, 5 );
    //

    m_panel8->SetSizer( bSizer11 );
    m_panel8->Layout();
    bSizer11->Fit( m_panel8 );
    //
    wScrollSizer10->Add( m_panel8, 1, wxEXPAND | wxALL, 5 );
}

void MyDialog::putAListItem(){

}